package com.luojing.innerclass.controllerframework;

/**
 * @author luojing
 * @create 2018/09/08 上午11:41
 **/
public class GreenHouseControls extends Controller {

  private boolean light = false;

  public class LightOn extends Event{

    public LightOn(long dalayTime) {
      super(dalayTime);
    }

    @Override
    public void action() {
      light = true;
    }

    @Override
    public String toString(){
      return "Light is on";
    }
  }

  public class LightOff extends Event{

    public LightOff(long dalayTime) {
      super(dalayTime);
    }

    @Override
    public void action() {
      light = false;
    }

    @Override
    public String toString(){
      return "Light is off";
    }
  }

  private boolean water = false;

  public class WaterOn extends Event{

    public WaterOn(long dalayTime) {
      super(dalayTime);
    }

    @Override
    public void action() {
      water = true;
    }

    @Override
    public String toString() {
      return "water is on";
    }
  }

  public class WaterOff extends Event{


    public WaterOff(long dalayTime) {
      super(dalayTime);
    }

    @Override
    public void action() {
      water = false;
    }

    @Override
    public String toString() {
      return "water is off";
    }
  }

  private String thermostatDay = "day";

  public class ThermostatNight extends Event{

    public ThermostatNight(long dalayTime) {
      super(dalayTime);
    }

    @Override
    public void action() {
      thermostatDay = "Night";
    }

    @Override
    public String toString() {
      return "thermostat is Night";
    }
  }

  public class ThermostatDay extends Event{

    public ThermostatDay(long dalayTime) {
      super(dalayTime);
    }

    @Override
    public void action() {
      thermostatDay = "Day";
    }

    @Override
    public String toString() {
      return "thermostat is day";
    }
  }

  public class Bell extends Event{

    public Bell(long dalayTime) {
      super(dalayTime);
    }

    @Override
    public void action() {
      addEvent(new Bell(dalayTime));
    }

    @Override
    public String toString() {
      return "Bing";
    }
  }

  public class Restart extends Event{

    private Event[] events;

    public Restart(long dalayTime,Event[] events) {
      super(dalayTime);
      this.events = events;
      for(Event e: events){
        addEvent(e);
      }
    }

    @Override
    public void action() {
      for(Event e : events){
        e.start();
        addEvent(e);
      }
      start();
      addEvent(this);
    }

    @Override
    public String toString() {
      return "Restart System";
    }
  }

  public static class Terminate extends Event{

    public Terminate(long dalayTime) {
      super(dalayTime);
    }

    @Override
    public void action() {
      System.exit(0);
    }

    @Override
    public String toString() {
      return "Terminating";
    }
  }
}
